package copyengine.utils.delayEffect.effect.basic
{
	import copyengine.utils.delayEffect.effect.ICEDelayEffect;

	public class CEDelayOrdinalExecuteBranchEffect extends CEDelayContainBranchEffectBasic
	{
		private var branchExecuteFinishNum:int = 0;
		private var currentBranchFlowExecuteStep:int = -1;


		public function CEDelayOrdinalExecuteBranchEffect()
		{
			super();
		}

		//============================================//
		//==Protected  Function
		//============================================//
		/**
		 * <b>开始按顺序执行子Branch</b>
		 */
		protected final function startOrdinalExecuteBranchEffect():void
		{
			if (subBranchEffectVector.length > 0)
			{
				currentBranchFlowExecuteStep = -1;
				tryToExecuteNextBranchFlow();
			}
			else
			{
				onAllBranchFlowFinish();
				onAllBranchExecuteFinish();
			}
		}

		//============================================//
		//==OverrideAble  Function
		//============================================//

		protected function onAllBranchExecuteFinish():void
		{
		}

		protected function onAllBranchFlowFinish():void
		{
		}

		//============================================//
		//==Private  Function
		//============================================//
		private function tryToExecuteNextBranchFlow():void
		{
			currentBranchFlowExecuteStep++;
			if (currentBranchFlowExecuteStep < subBranchEffectVector.length)
			{
				var effect:ICEDelayEffect = subBranchEffectVector[currentBranchFlowExecuteStep];
				effect.execute(tryToExecuteNextBranchFlow, onBranchExecuteFinish);
			}
			else
			{
				onAllBranchFlowFinish();
			}
		}

		private function onBranchExecuteFinish():void
		{
			branchExecuteFinishNum++;
			if (branchExecuteFinishNum >= subBranchEffectVector.length)
			{
				onAllBranchExecuteFinish();
			}
		}

	}
}
